package com.twu.biblioteca;

import com.sun.org.apache.xpath.internal.NodeSet;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: twer
 * Date: 5/21/13
 * Time: 8:42 AM
 * To change this template use File | Settings | File Templates.
 */
public class Library {
    private static Map<Book, Integer> books = new HashMap<Book, Integer>();
    private static List<Book> bookList = new ArrayList<Book>();
    private static Map<Movie, Integer> movies = new HashMap<Movie, Integer>();
    private static List<Movie> movieList = new ArrayList<Movie>();

    public List<Book> getBooks() {
        return bookList;
    }

    public void addBookListItem(Book book, int quantity) {
        bookList.add(book);
        books.put(book, quantity);
    }

    public boolean reserveById(int id){
        return reserveByName(bookList.get(id).getName());
    }

    public boolean reserveByName(String bookName) {
        Book book = new Book(bookName);
        if(!books.containsKey(book))
            return false;

        if(books.get(book) == 0)
            return false;

        books.put(book, books.get(book) - 1);
        return true;
    }

    public List<Movie> getMovies() {
        return movieList;
    }

    public void addMovieListItem(Movie movie, int quanity) {
        movieList.add(movie);
        movies.put(movie, quanity);
    }

    public static Library createLibrary(){
        Library lib = new Library();
        lib.addBookListItem(new Book("TDD"), 3);
        lib.addBookListItem(new Book("TDD by example"), 1);
        lib.addBookListItem(new Book("Refactor"), 2);

        Movie movie1 = new Movie("TEST1", "1921", "TEST1");
        Movie movie2 = new Movie("TEST2", "1921", "TEST1");
        Movie movie3 = new Movie("TEST3", "1921", "TEST1");
        Movie movie4 = new Movie("TEST4", "1921", "TEST1");
        Movie movie5 = new Movie("TEST5", "1921", "TEST1");
        Movie movie6 = new Movie("TEST6", "1921", "TEST1");
        Movie movie7 = new Movie("TEST7", "1921", "TEST1");
        Movie movie8 = new Movie("TEST8", "1921", "TEST1");
        Movie movie9 = new Movie("TEST9", "1921", "TEST1");
        Movie movie10 = new Movie("TEST10", "1921", "TEST1");
        Movie movie11 = new Movie("TEST11", "1921", "TEST1");
        Movie movie12 = new Movie("TEST12", "1921", "TEST1");
        Movie movie13 = new Movie("TEST13", "1921", "TEST1");
        Movie movie14 = new Movie("TEST14", "1921", "TEST1");
        Movie movie15 = new Movie("TEST15TEST15TEST15TEST15TEST15", "1921", "TEST1TEST15TEST15TEST15");
        movie1.setRating("7.6");
        movie2.setRating("7.6");
        movie4.setRating("7.6");
        movie6.setRating("7.6");
        movie7.setRating("7.6");
        movie8.setRating("7.6");
        movie10.setRating("7.6");
        movie11.setRating("7.6");
        movie12.setRating("7.6");
        movie15.setRating("7.6");

        lib.addMovieListItem(movie1,1);
        lib.addMovieListItem(movie2,1);
        lib.addMovieListItem(movie3,1);
        lib.addMovieListItem(movie4,1);
        lib.addMovieListItem(movie5,1);
        lib.addMovieListItem(movie6,1);
        lib.addMovieListItem(movie7,1);
        lib.addMovieListItem(movie8,1);
        lib.addMovieListItem(movie9,1);
        lib.addMovieListItem(movie10,1);
        lib.addMovieListItem(movie11,1);
        lib.addMovieListItem(movie12,1);
        lib.addMovieListItem(movie13,1);
        lib.addMovieListItem(movie14,1);
        lib.addMovieListItem(movie15,1);

        return lib;
    }
}
